package com.kerwin.rolesys;

import com.kerwin.entity.returnjson.AxiosResultGenerics;
import com.kerwin.entity.returnjson.E;
import com.kerwin.entity.returnjson.TableDate;
import com.kerwin.rolemgt.RoleService;
import com.kerwin.rolemgt.entity.Department;
import com.kerwin.rolemgt.entity.Role;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/role")
public class RoleHandler {

    @Resource
    RoleService roleService;

    /*返回部门下拉菜单的*/
    @RequestMapping("/depart")
    public AxiosResultGenerics<TableDate> getDepart(){
        List<Department> depart = roleService.findDepart();
        return AxiosResultGenerics.SUC(depart);
    }

    @PostMapping("/addRole")
    public void addRole(@RequestBody Role role){
        //System.out.println(role.toString());
        roleService.getRole(role);

    }

    @RequestMapping("/queryRole")
    public AxiosResultGenerics queryRole(){
        List<Role> roles = roleService.queryRole();
        return AxiosResultGenerics.SUC(E.SUC, roles);
    }


    @RequestMapping("/queryRoleName")
    public AxiosResultGenerics queryRoleName(){
        List<Role> roles = roleService.getRoleName();
        return AxiosResultGenerics.SUC(E.SUC, roles);
    }


}
